<template>
  <van-nav-bar title="首页" />

  <div class="swipe-wrap">
    <van-search
      v-model="value"
      placeholder="请输入搜索关键词"
      class="sh"
      background="transparent"
      shape="round"
    />
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
      <van-swipe-item v-for="item in list" :key="item">
        <img :src="item" alt="" />
      </van-swipe-item>
    </van-swipe>
  </div>

  <van-grid>
    <van-grid-item text="每日福利">
      <template #icon>
        <span>🍉</span>
      </template>
    </van-grid-item>

    <van-grid-item icon="photo-o" text="热销榜" />
    <van-grid-item icon="photo-o" text="每日福利" />
    <van-grid-item icon="photo-o" text="热销榜" />
  </van-grid>
</template>

<script setup lang="ts">
import { onMounted, ref } from "vue";

const list = ref<string[]>([]);
onMounted(() => {
  fetch("http://www.pudge.wang:4000/home/banner")
    .then((response) => response.json())
    .then((res) => {
      console.log(res);
      if (res.status === "0") {
        list.value = res.result.list;
      }
    });
});

const value = ref<string>("");
</script>

<style lang="less" scoped>
.my-swipe .van-swipe-item {
  width: 100%;
  height: 200px;

  img {
    width: 100%;
    height: 100%;
  }
}

// :deep()表示css可以去影响子组件的样式
:deep(.van-swipe__indicator) {
  width: 20px;
  height: 4px;
  background-color: lightcoral;
  border-radius: 0;
}

.swipe-wrap {
  position: relative;
}

.sh {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 99;
  width: 100%;
}

:deep(.van-search__content) {
  background-color: rgba(255, 255, 255, 0.5);
}

:deep(#van-search-1-input::placeholder) {
  color: #fff;
}
</style>
